<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    function twoSum(nums, target) {
      let map = new Map()
      for (let i = 0; i < nums.length; i++) {
        let temp = target - nums[i]
        if (map.has(nums[i])) {
          return [map.get(nums[i]), i]
        }
        map.set(temp, i)
      }
      return []
    }
    console.log("Two Sum:", twoSum([2, 7, 11, 15], 9)) // [0, 1]
  </script>
</html>
